package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    public List<Company> findAll() {
        return companyDao.findAll();
    }

    //保存企业
    public void save(Company company) {
        company.setId(UUID.randomUUID().toString());
        companyDao.save(company);
    }

    //根据ID查询
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    //更新
    public void update(Company company) {
        companyDao.update(company);
    }

    //根据ID删除企业
    public void delete(String id) {
        companyDao.delete(id);
    }

    @Override
    public PageInfo findPageByHelper(int page, int size) {
        //设置分页参数
        PageHelper.startPage(page, size);
        //调用dao查询全部
        List<Company> list = companyDao.findAll();
        //构造返回值
        return new PageInfo(list);
    }
}
